#include<iostream>
#include<pthread.h>
#include<vector>
#include<unistd.h>
#include<string>
#include<cstdlib>
#include<cstdio>
#include<cstring>
using namespace std;
int tickets=1000;
pthread_mutex_t mutex;//先声明
void* run(void* arge)
{
    pthread_mutex_lock(&mutex);
    //char* tem=(char* )arge;
    while(tickets>0)
    {
        cout<<(char*)arge<<" get tickets:"<<tickets--<<endl;
        sleep(1);
        //printf("%s get ticket:%d\n",(char* )arge,tickets--);
        //cout<<(char* )arge<<endl;
    }
    pthread_mutex_unlock(&mutex);
    return 0;
}

int main()
{
    pthread_mutex_init(&mutex,NULL);//动态分配
    vector<pthread_t> data;
    for(int i=0;i<10;i++)
    {
        pthread_t tem;
        //string arge="pthread "+(to_string(i));
        char str_tem[100];
        string arge=("pthread "+to_string(i));
        strcpy(str_tem,arge.c_str());
        pthread_create(&tem,NULL,run,str_tem);
        data.push_back(tem);
    }
    for(auto& pthread:data)
    {
        pthread_join(pthread,NULL);
    }
    pthread_mutex_destroy(&mutex);//
    return 0;
}